<template>
    <exPubTable ref="detailTable" :cfg.sync="detailcfg" :exData="detailList" @getDataList="queryDetailInfo"  :diffHeight="60" :defPageSize="500" :show-summary="true"></exPubTable>
</template>


<script>

export default {
    props:["qry"],
    data() {
        var that =this;
        return {
            totalMoney: 0,
            detailList:[],
            detailcfg:{
                showIndex: true,
                usePage:true,
                btnsWidth: 100,
                btns:[
                    {name:"删除",handle:({row,$index})=>{
                        this.detailList.splice($index,1);
                    }}
                ],
                columns: [
                    {prop:"tradeno",label:"编号",width:140},
                    {prop:"day",label:"日期",width:80,sortable:true},
                    {prop:"time",label:"时间",width:70,sortable:true},
                    {prop:"code",label:"代码",width:70,sortable:true},
                    {prop:"name",label:"名称",width:80,sortable:true},
                    {prop:"isBuy",label:"卖买方向",width:70,dictList:[{name:"买入",value:1},{name:"卖出",value:0}],getColor(s){return that.getRateColor(0-s.row.money)}},
                    {prop:"type",label:"交易类别",width:80,getColor(s){return that.getRateColor(0-s.row.money)}},
                    {prop:"amount",label:"数量",width:60,sumType:"add",getColor(s){return that.getRateColor(0-s.row.money)}},
                    {prop:"price",label:"均价",width:70,getColor(s){return that.getRateColor(0-s.row.money)}},
                    {prop:"money",label:"金额",width:80,sumType:"add",formatter:(row,col,val,idx,isSum)=>{
                        if(isSum){
                            if(row.amount!=0){
                                var price = that.detailList[0].price;
                                var money = that.fixed((row.amount*price)+val);
                                return "<span title='修正数量后的值,取最新一笔价格计算' style='color:blue'>"+money+"</span>";
                            }
                        }
                        return that.fixed(val);
                    },getColor(s){return that.getRateColor(0-s.row.money)}},
                    {prop:"totalFee",label:"总手续费",width:70,sumType:"add",formatter:this.fixed2},
                    {prop:"leftNum",label:"剩余数量",width:70},
                    {prop:"fee1",label:"佣金",width:70,sumType:"add",formatter:this.fixed2},
                    {prop:"fee2",label:"规费",width:70,sumType:"add",formatter:this.fixed2},
                    {prop:"fee3",label:"印花税",width:70,sumType:"add",formatter:this.fixed2},
                    {prop:"fee4",label:"过户费",width:70,sumType:"add",formatter:this.fixed2},
                    {prop:"leftmoney",label:"剩余金额",width:90,formatter:this.fixed2},
                    {prop:"account",label:"股东账号",width:100},
                    {prop:"market",label:"交易市场",width:70},

                ],
            },
        }
    },

    mounted() {
    },
    inject:["getQueryInfo"],

    methods: {
        reQuery(){
            if(this.$refs.detailTable) this.$refs.detailTable.reQuery();
        },
        queryDetailInfo(pInfo){
            var opername = "queryDetailInfo";
            this.registerListen(this,opername,(res)=>{
                if(res.succ){
                    pInfo.total = res.data.total;
                    this.detailList = res.data.records;
                    this.detailList.map((item)=>{
                        item.totalFee = item.fee1+item.fee2+item.fee3+item.fee4;
                    })
                }else{
                    this.$message.error("查询异常:"+res.err)
                }
            });
            var arg = this.getQueryInfo();
            
            var param = {type:"commonQry",name:opername,table:"tradehis",objInfo:arg};
            param.order = "day desc,time desc";
            param.count = true;
            if(pInfo){
                param.pInfo=`${pInfo.page},${pInfo.size}`
            }
            electron.ipcRenderer.send("doSql",param)
        },
    }
    
}
</script>

<style lang="less">

</style>
